#基础
person_info = {
    "name": "Alex",
    "age": 30,
    "country": "USA",
    "language": ["English", "Spanish"],
    "is_student": False
}
# print(person_info['name'])
person_info['age'] = 31
person_info['height'] = 175
for i in range(1,4):
    person_info[f"hobby{i}"] = f"hobby{i}"
print(person_info)
person_info['language'].append("French")
print(person_info)

person_info['language'] = ["English"]
print(len(person_info['language']))
print(person_info['language'])
person_info.update({'email':'alex@example.com'})
print(person_info)

for x in person_info.items():
    print(x, end=' ')
for i in person_info.keys():
    print(i, end=' ')
print(person_info)

#进阶
employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    }
}
new_employee_id = 102
new_employee = {
    "name": "Bob",
    "age": 28,
    "gender": "Male",
    "position": "Software Engineer",
    "team": "Development",
    "salary_history": [65000, 75000]
}
employees[new_employee_id] = new_employee
# print(employees)

employees_id_todel = 102
if employees_id_todel in employees:
    del employees[employees_id_todel]
# print(employees)

if 101 in employees:
    employees[101]['age'] = 31
    # print(employees[101]['age'])
if 101 in employees:
    employees[101]['salary_history'].append(95000)
    # print(employees[101]['salary_history'])

if 101 in employees:
    salary_history = employees[101]['salary_history']
    average_salary = sum(salary_history)/ len(salary_history)
    # print(average_salary)

older_employees = {}
for emp_id, emp_info in employees.items():
    if emp_info['age'] > 25:
        older_employees[emp_id] = emp_info['name']
        # print(older_employees)

for emp_info in employees.values():
    if emp_info['salary_history']:
        last_salary = emp_info['salary_history'][-1]
        emp_info['bonus'] = last_salary * 0.1
        # print(employees)

if 101 in employees:
    employees[101]['position'] = 'Senior Data Scientist'
    # print(employees[101]['position'])

for emp_info in employees.values():
    if 'gender' in emp_info:
        del emp_info['gender']
    # print(employees)

new_employees = {}
for emp_id, emp_info in employees.items():
    new_employees[emp_id] = {
        'name': emp_info['name'],
        'position': emp_info['position']
    }
    # print(new_employees)